package test42;

import java.io.*;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-05-13
 * Time: 17:21
 */
public class Main1 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    static int[] X = {-1, 1, 0, 0};
    static int[] Y = {0, 0, -1, 1};

    public static void main(String[] args) throws IOException {
        String str = null;
        while ((str = br.readLine()) != null) {
            char[][] arr = new char[10][10];
            arr[0] = str.toCharArray();
            for (int i = 1; i < 10; i++) {
                arr[i] = br.readLine().toCharArray();
            }
            int[][] map = new int[10][10];
            for (int i = 0; i < 10; i++) {
                Arrays.fill(map[i], Integer.MAX_VALUE);
            }
            map[0][1] = 0;
            bfs(0, 1, arr, map);
            bw.write(map[9][8] + "\n");
        }
        bw.flush();
        bw.close();
        br.close();
    }

    public static void dfs(int x, int y, char[][] maze, int[][] map) {
        for (int i = 0; i < 4; i++) {
            int xx = x + X[i];
            int yy = y + Y[i];
            if (xx >= 0 && xx < 10 && yy >= 0 && yy < 10 && maze[xx][yy] == '.' && map[xx][yy] > map[x][y] + 1) {
                map[xx][yy] = map[x][y] + 1;
                dfs(xx, yy, maze, map);
            }
        }
    }

    public static void bfs(int x, int y, char[][] maze, int[][] map) {
        Deque<int[]> queue = new LinkedList<>();
        queue.offer(new int[]{x, y});
        while (!queue.isEmpty()) {
            int[] temp = queue.poll();
            for (int i = 0; i < 4; i++) {
                int xx = temp[0] + X[i];
                int yy = temp[1] + Y[i];
                if (xx >= 0 && xx < 10 && yy >= 0 && yy < 10 && maze[xx][yy] == '.' && map[xx][yy] > map[temp[0]][temp[1]] + 1) {
                    map[xx][yy] = map[temp[0]][temp[1]] + 1;
                    queue.offer(new int[]{xx, yy});
                }
            }
        }
    }
}


